package helper.graph

import com.mxgraph.layout.mxCircleLayout
import com.mxgraph.swing.mxGraphComponent
import helper.graph.JGraphHelper.visualizeGraph
import helper.scxml.scxml2.t0.case2_traffic.zone.TrafficEnvHelper.TrafficEnv.Companion.makeTrafficEnv
import helper.scxml.scxml2.t0.case1_cycle.zone.CycleEnvHelper.CycleEnv.Companion.makeCycleEnv
import org.jgrapht.Graph
import org.jgrapht.ext.JGraphXAdapter
import org.jgrapht.graph.DefaultDirectedGraph
import org.jgrapht.graph.DefaultEdge
import javax.swing.JFrame

internal class JGraphHelperTest {
    object Ts {
        object T0 {
            @JvmStatic
            fun main(args: Array<String>) {
                // 创建一个有向图
                val g: Graph<String, DefaultEdge> = DefaultDirectedGraph(DefaultEdge::class.java)

                // 添加顶点
                val vertices = listOf("s0", "s1", "s2", "s3", "s4")
                vertices.forEach { g.addVertex(it) }

                // 添加边
                g.addEdge("s0", "s1")
                g.addEdge("s1", "s2")
                g.addEdge("s1", "s3")
                g.addEdge("s1", "s4")
                g.addEdge("s2", "s4")
                g.addEdge("s3", "s4")

                // 创建一个适配器
                val jgxAdapter = JGraphXAdapter(g)

                // 创建一个布局
                val layout = mxCircleLayout(jgxAdapter)

                // 应用布局
                layout.execute(jgxAdapter.defaultParent)

                // 创建一个 Swing 窗口来显示图
                val frame = JFrame()
                frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
                frame.setSize(400, 400)

                val graphComponent = mxGraphComponent(jgxAdapter)
                frame.contentPane.add(graphComponent)
                frame.isVisible = true
            }
        }

        object T1 {
            @JvmStatic
            fun main(args: Array<String>) {
                visualizeGraph(makeCycleEnv().aStateEventStateLHM)
            }
        }

        object T2 {
            @JvmStatic
            fun main(args: Array<String>) {
                visualizeGraph(makeTrafficEnv().aStateEventStateLHM)
            }
        }
    }


}